/*
 * @Author: lz08 liuzheng@ceepower.com
 * @Date: 2022-11-30 14:47:25
 * @LastEditors: lz08 liuzheng@ceepower.com
 * @LastEditTime: 2022-11-30 16:51:05
 * @FilePath: \vue3-ts-cms\src\permission.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import router from './router'
import Cookies from 'js-cookie'

const whiteList = ['/login'];
router.beforeEach(async (to, from, next) => {
  const hasToken = Cookies.get("system_token")
  if (hasToken) {
    // 如果已经登录，路由还是登录页面的话，直接重定向至主页
    if (to.path === '/login') {
      next({path:'/'})
    } else {
      next()
    }
  } else {
    if (whiteList.indexOf(to.path) !== -1) {
      next()
    } else {
      next(`/login?redirect=${to.path}`)
    }
  }
})

router.afterEach((to) => {})
